package pl.register.android;

import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import pl.register.android.course.Course;
import pl.register.android.course.factory.AsyncCourseCreator;
import pl.register.android.course.factory.CreatorCourseMonitoring;
import pl.register.android.storage.external.CheckerSDCard;
import pl.register.android.storage.external.CourseRegisterSDCardManager;
import pl.register.android.course.dialog.DatabaseCreatorDialogBuilder;
import roboguice.activity.RoboActivity;

/**
 * @author Mateusz Strzelecki
 * @since 2013-05-05
 */
public class ValidationActivity extends RoboActivity implements CreatorCourseMonitoring {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if (CheckerSDCard.isAvailable(this)) {
            if (CourseRegisterSDCardManager.databaseNotExist()) {
                new DatabaseCreatorDialogBuilder(this).create().show();
            } else {
                startHomeActivity();
            }
        }
    }

    public void createCourseFor(int startYearCourse) {
        new AsyncCourseCreator(this, this, startYearCourse).execute();
    }

    public void startHomeActivity() {
        startActivity(new Intent(this, HomeActivity.class));
        finish();
    }

    @Override
    public void insertedNewCourse(Course course) {
        startHomeActivity();
    }
}